package com.yami.shop.delivery.api.listener;

import com.yami.shop.bean.app.dto.OrderSelfStationDto;
import com.yami.shop.bean.app.dto.ShopCartOrderMergerDto;
import com.yami.shop.bean.event.GetUserStationEvent;
import com.yami.shop.delivery.common.service.OrderSelfStationService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 获取用户的常用自提信息
 *
 * @author lhd
 */
@Component("getUserStationListener")
@AllArgsConstructor
public class GetUserStationListener {

    private final OrderSelfStationService orderSelfStationService;

    /**
     * 获取用户的常用自提信息
     */
    @EventListener(GetUserStationEvent.class)
    public void getUserStationListenerEvent(GetUserStationEvent event) {
        List<OrderSelfStationDto> userStation = orderSelfStationService.getUserStation(event.getUserId());
        ShopCartOrderMergerDto shopCartOrderMergerDto = event.getShopCartOrderMergerDto();
        shopCartOrderMergerDto.setOrderSelfStationList(userStation);
    }

}
